# Maintainer: gym603 <gui_yuan_miao@163.com>

_realname=absl-py
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.8.1
pkgrel=1
pkgdesc="Abseil Common Libraries (Python) (mingw-w64)"
arch=('any')
url="https://github.com/abseil/abseil-py"
license=('Apache 2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
_archive=abseil-py-pypi-v${pkgver}
source=(${_archive}.tar.gz::https://github.com/abseil/abseil-py/archive/pypi-v${pkgver}.tar.gz)
sha256sums=('0a145cb81101d1add8b87eaae58c5d51521084bf7cc4e4654928b326a864c6c3')

_deps=('six')
_deps2=('enum34')
_deps3=()

build() {
  cd "${srcdir}"
  rm -rf python{2,3}-build
  for builddir in python{2,3}-build; do
    msg2 "Building for ${CARCH} ${builddir%-build} ..."
    cp -r ${_archive} ${builddir}
    pushd $builddir
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py --quiet build
    popd
  done
}

package_python3-absl-py() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3" "${_deps[@]/#/${MINGW_PACKAGE_PREFIX}-python3-}" "${_deps3[@]/#/${MINGW_PACKAGE_PREFIX}-python3-}")

  cd "${srcdir}/python3-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py --quiet install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-absl-py() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2" "${_deps[@]/#/${MINGW_PACKAGE_PREFIX}-python2-}" "${_deps2[@]/#/${MINGW_PACKAGE_PREFIX}-python2-}")

  cd "${srcdir}/python2-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py --quiet install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-absl-py() {
  package_python2-${_realname}
}

package_mingw-w64-i686-python3-absl-py() {
  package_python3-${_realname}
}

package_mingw-w64-x86_64-python2-absl-py() {
  package_python2-${_realname}
}

package_mingw-w64-x86_64-python3-absl-py() {
  package_python3-${_realname}
}
